package fun.codedesign.yinxue.code.php2java.rule.statement;

public class ImportStatementRule implements StatementRule{
    @Override
    public boolean isMatch(String originStatement) {
        return true;
    }

    @Override
    public String invoke(String originStatement) {
        // 不包含 / 时, 不用替换
        if (!originStatement.contains("\\")) {
            return originStatement;
        }
        // 1. 除后缀Class的前面小写 2. 替换 / 为.
        String replaceStatement = originStatement.replace("\\",".");
        int lastDotIndex = replaceStatement.lastIndexOf(".");
        String className = replaceStatement.substring(lastDotIndex+1);
        String importPrefix = replaceStatement.substring(0, lastDotIndex);
        String newStatment = importPrefix.toLowerCase() +"."+ className;
        return newStatment;
    }
}
